package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-09-20
 * Time: 11:47
 */
// 使用 spring boot 操作 redis
    // 1.添加依赖
    // 2.添加连接配置
    // 3.根据 redis api 操作 redis
@RestController
public class TestController {
    // 自动装配
    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/setval")
    public void setVal(String val) {
        redisTemplate.opsForValue().set("remote",val,1000, TimeUnit.SECONDS);
    }

    @RequestMapping("/getval")
    public String getValue() {
        return (String) redisTemplate.opsForValue().get("remote");
    }


}
